package com.wt.test.ai.springai.config;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 聊天客户端配置类
 *
 * @author qiyu
 * @since 2025/1/25
 */
@Configuration
@RequiredArgsConstructor
public class ChatClientConfig {
    
    private final ChatModel chatModel;
    
    private final EmbeddingModel embeddingModel;
    
    @Bean
    public ChatClient chatClient(VectorStore vectorStore) {
        return ChatClient.builder(chatModel)
                .defaultSystem("你是一个友善且幽默的对话机器人，使用{voice}的语言风格。")
                .defaultAdvisors(
                        new MessageChatMemoryAdvisor(new InMemoryChatMemory()), // CHAT MEMORY
//                        new QuestionAnswerAdvisor(vectorStore), // RAG
                        new SimpleLoggerAdvisor())
                .build();
    }
    
    @Bean
    public VectorStore vectorStore() {
        return SimpleVectorStore.builder(embeddingModel)
                .build();
    }
}
